public class Offer47 {
    public int maxValue(int[][] grid) {
        int row = grid.length;
        int col = grid[0].length;
        int[] dp = new int[col+1];
        for (int i = 1; i < row+1; i++) {
            for (int j = 1; j <col+1 ; j++) {
                dp[j] = Math.max(dp[j],dp[j-1])+grid[i-1][j-1];
            }
        }
        return dp[col];
    }
}
